<template>
  <div class="content">
    <el-backtop :visibility-height="100" :bottom="60" />
    <el-card class="bottom10">
      <el-button type="success" size="mini" plain>全部（{{ total }}）</el-button>
      <el-button type="danger" size="mini" plain>待拆单（{{0 }}）</el-button>
      <el-button type="warning" size="mini" plain>已拆单（{{0 }}）</el-button>
      <el-collapse v-model="activeNames" style="margin-top:10px">
        <el-collapse-item name="1">
          <template slot="title">
            <span style="font-size:18px;">筛选查询</span>
          </template>
          <el-form ref="form" :model="form" label-width="100px">
            <div class="search-class">
              <el-form-item label="用户id：">
                <el-input v-model="form.openid" placeholder="用户openid" clearable />
              </el-form-item>
              <el-form-item label="收货人：">
                <el-input v-model="form.user_name" placeholder="收货人姓名" clearable/>
              </el-form-item>
              <el-form-item label="手机号：">
                <el-input v-model="form.phone" placeholder="手机号" clearable/>
              </el-form-item>
              <!-- <el-form-item label="拆单状态：">
                <el-select v-model="form.state" placeholder="请选择" clearable>
                  <el-option v-for="item in $orderSplitOption" clearable :label="item.label" :value="item.value" :key="item.value"> </el-option>
                </el-select>
              </el-form-item> -->
              <el-form-item label="提交时间：">
                <el-date-picker v-model="form.createdate" :unlink-panels="true" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"> </el-date-picker>
              </el-form-item>
              <el-form-item label="">
                <el-button type="primary" icon="el-icon-search" @click.enter="search">查询</el-button>
              </el-form-item>
            </div>
          </el-form>
        </el-collapse-item>
      </el-collapse>
      <el-row class="flex-hs">
        <el-table :data="tableData" border style="width: 100%;margin:20px 0" @selection-change="handleSelectionChange">
          <el-table-column type="selection" label="" width="50" />
          <!-- <el-table-column type="index" label="序号" width="50" /> -->
          <el-table-column prop="openid" label="客户id" width="150" />
          <el-table-column prop="name" label="客户名称" />
          <el-table-column prop="phone" label="联系方式" />
          <el-table-column prop="area" label="服务地址" min-width="150" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
              <span>{{scope.row.province+scope.row.city+scope.row.town+scope.row.detail}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="" label="用户来源" >
           <template slot-scope="scope">
              <span>微信小程序</span>
            </template>
          </el-table-column>
          <el-table-column prop="split_state" label="拆单状态">
            <template slot-scope="scope">
              <el-tag type="success" v-if="scope.row.num">已拆单</el-tag>
              <el-tag type="primary" v-else>无需拆单</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="" label="发送状态">
           <template slot-scope="scope">
              <el-tag type="success" v-if="scope.row.show_state==1">已推送</el-tag>
              <el-tag type="danger" v-if="scope.row.show_state==2">未推送</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="60">
            <template slot-scope="scope">
              <el-dropdown @command="handleCommand">
                <span class="el-dropdown-link">
                  <i class="el-icon-more-outline" />
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item :command="whatIclick('splitOrder', scope.row)">拆单</el-dropdown-item>
                  <!-- <el-dropdown-item :command="whatIclick('look', scope.row)">查看</el-dropdown-item> -->
                  <!-- <el-dropdown-item :command="whatIclick('edit', scope.row)">编辑</el-dropdown-item> -->
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <el-row class="flex-he">
        <el-pagination :current-page="currentPage" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </el-row>
    </el-card>
    <look-info v-if="openLookInfo" ref="lookInfo" />
    <!-- <add-or-upload v-if="openAddOrUpload" ref="addOrUpload" /> -->
    <splid-order v-if="openSplitOrder" ref="splitOrder" @save="search"/>
  </div>
</template>

<script>
import lookInfo from './lookInfo'
// import addOrUpload from './addOrUpload'
import splidOrder from '../../common/spliteOrder.vue'
import { mapState } from 'vuex'
export default {
  components: {
    lookInfo,
    // addOrUpload
    splidOrder
  },
  data() {
    return {
      activeNames: ['1'],
      currentPage: 1,
      pageSize: 20,
      total: 0,
      orderNumlist:[],
      nopay:'0',
      payed:'0',
      canceled:'0',
      deled:'0',
      form: {
        openid:'',
        user_name: '',
        phone:'',
        createdate: '',
        state: ''
      },
      openLookInfo: false,
      openAddOrUpload:false,
      openSplitOrder: false,
      multipleSelection: [],
      cateData:[],
      tableData: [

      ],
      moreproInfo: {
        id:'',
        num:'',
        pname:'',
        ggObj:{},
        px:'',
        desc:'备注'
      },
      json_fields: {
        '头部-诊断名称': 'name', //常规字段
        '头部-联系电话': 'phone.mobile', //支持嵌套属性
        '头部-损坏区域代码': {
          field: 'phone.landline',
          //自定义回调函数
          callback: value => {
            return `损坏区域代码 - ${value}`
          }
        }
      },
      json_data: [
        {
          name: '损坏的组件一',
          city: 'New York',
          country: 'United States',
          birthdate: '1978-03-15',
          phone: {
            mobile: '1-541-754-3010',
            landline: '(541) 754-3010'
          }
        },
        {
          name: '损坏的组件二',
          city: 'Athens',
          country: 'Greece',
          birthdate: '1987-11-23',
          phone: {
            mobile: '+1 855 275 5071',
            landline: '(2741) 2621-244'
          }
        }
      ]
    }
  },
  computed: {
    ...mapState(['$orderSplitOption', '$state']),
    // state id order by openid user_name createdate page count
    queryData() {
      let obj = this.form
      obj.count = this.pageSize
      obj.page = this.currentPage
      return obj
    }
  },
  created() {
    this.search()
  },
  methods: {
    search() {
      this.$http.httpPost('/user/addressInfoList', this.queryData).then(res=>{
        console.log(res,789);
        if (res.data.code == 0) {
          this.total = res.data.data.count
          this.tableData = res.data.data.data
          this.getCateData()
        }
      })
      
    },
    getCateData() {
      this.$http.httpPost('/cate/cateList').then(res => {
        if (res.data.code == 0) {
          let arr = res.data.data.data
          let arr22 = this.dataDoJson(arr, 0, 1)
          let arr33 = arr22.filter(item => [15, 16].indexOf(item.id) == -1)
          this.cateData = JSON.parse(JSON.stringify(arr33))
        }
      })
    },
     // 递归处理数据
    dataDoJson(data, pid, level) {
      const result = []
      let temp = []
      for (let i = 0; i < data.length; i++) {
        if (data[i].pid === pid) {
          const obj = data[i]
          obj.level = level
          obj.products = [this.moreproInfo]
          temp = this.dataDoJson(data, data[i].id, level + 1)
          if (temp.length > 0) {
            obj.children = temp
          } else {
            obj.children = []
          }
          result.push(obj)
        }
      }
      return result
    },
    outOrder(val) {},
    whatIclick(type, data) {
      return {
        type,
        data
      }
    },
    deleteItem(val) {
      const idarr = []
      if (val === 1) {
        this.multipleSelection.forEach(e => {
          idarr.push(e.id)
        })
      } else {
        idarr.push(val.id)
      }
      const ids = idarr.join()
      this.$confirm('此操作将删除该项目, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let res = this.$http.httpPost('/brand/delBrand', { ids: ids })
          if (res) {
            this.$operateTip('已完成！', '已完成数据删除！', 'success')
          }
          this.search()
        })
        .catch(() => {
          this.$operateTip('已取消！', '已取消数据删除！', 'info')
        })
    },
    handleCommand(e) {
      if (e.type === 'splitOrder') {
        this.openSplitOrder = true
        this.$nextTick(() => {
          this.$refs.splitOrder.init(e.data,this.cateData)
        })
      } else if (e.type === 'look') {
        this.openLookInfo = true
        this.$nextTick(() => {
          this.$refs.lookInfo.init(e.data, 1)
        })
      } else if (e.type === 'edit') {
        this.openAddOrUpload = true
        this.$nextTick(() => {
          this.$refs.lookInfo.init(e.data, 1)
        })
      }
    },
    openDo(id) {
      this.$prompt('客服备注', '输入备注', {
        inputType:'textarea',
        distinguishCancelAndClose:true,
        confirmButtonText: '保存备注',
        cancelButtonText: '取消',
        inputPattern: /^[\u4e00-\u9fffa-zA-Z0-9]{1,500}$/,
        inputErrorMessage: '必须填写备注,100字以内！'
      })
        .then(({ value }) => {
          let obj = {
            remark:value,
            id:id,
          }
          this.$http.httpPost('/order/orderUpdate', obj).then(res=>{
            if(res){
              this.$message.success('操作成功！')
              this.search()
            }
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消备注！'
          })
        })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.search()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.search()
    },
    // 列表多选
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  }
}
</script>
<style lang="less">

</style>
